﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for BaseClass
/// </summary>
public class BaseClass
{
	static SqlConnection cn;
    static BaseClass()
	{
		 cn = new SqlConnection("Data Source=.;Initial Catalog=BloodDonationManagementSystem;Integrated Security=True");
	}
    public static int RunDML(string query)
    {
        string sn = cn.State.ToString();
        if (sn == "Open")
            cn.Close();
        SqlCommand cm = new SqlCommand(query, cn);
        try
        {
            cn.Open();
             cm.ExecuteNonQuery();
             cn.Close();
            return 1;
        }
        catch
        {
            cn.Close();
            return 0;
        }
    }

    public static DataTable RunSelect(string cmd)
    {
        SqlCommand cm = new SqlCommand();
        cm.CommandText = cmd;
        cm.Connection = cn;
        DataTable dt = new DataTable();
        SqlDataAdapter adapter = new SqlDataAdapter(cm);
        try
        {
            adapter.Fill(dt);
            return dt;
        }
        catch
        {
            return new DataTable();
        }
    }
}